import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:namewava/pages/mine/widgets/jc_mine_comment_item.dart';
import 'package:namewava/utils/jc_cache.dart';
import 'package:namewava/utils/jc_image_path.dart';
import 'package:namewava/utils/jc_nav.dart';
import 'package:namewava/utils/jc_screenutil_info.dart';
import 'package:namewava/utils/jc_text_style.dart';

class JcSet extends StatefulWidget {
  const JcSet({super.key});

  @override
  State<JcSet> createState() => _JcSetState();
}

class _JcSetState extends State<JcSet> {
  RxString myId = ''.obs;
  String appName = '';
  RxBool translate = false.obs;
  @override
  void initState() {
    super.initState();
    myId.value = Get.arguments['userId'];
    var appInfo = JcCache.getInstance().get('appinfo');
    appName = jsonDecode(appInfo)['appName'];

    var isTranslate = JcCache.getInstance().get('isTranslate');
    if (isTranslate != null && isTranslate is bool) {
      translate.value = isTranslate;
    } else {
      translate.value = false;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: _setWidget(),
    );
  }

  _setWidget() {
    return Container(
      width: JcScreenutilInfo.screenWidth,
      height: JcScreenutilInfo.screenHeight,
      decoration: const BoxDecoration(
          image: DecorationImage(
              image: AssetImage(JcImagePath.jcMinePageBg), fit: BoxFit.fill)),
      child: Column(
        children: [
          JcNav(
            title: 'Setting',
            backFunction: () {
              Get.back();
            },
          ),
          SizedBox(
            height: 65.h,
          ),
          Image.asset(
            JcImagePath.jcWavaLogo,
            width: 100.w,
            height: 100.w,
          ),
          Text(
            appName,
            style: JcTextStyle.octoberDevanagariBoldTextStyle(
                17.sp, Colors.black,
                fWeight: FontWeight.w500),
          ),
          SizedBox(
            height: 25.h,
          ),
          Obx(() {
            return JcMineCommentItem(
                title: 'ID ${myId.value.substring(0, 6)}',
                imageIcon: JcImagePath.jcCopycon,
                type: ItemType.copy,
                copyValue: myId.value);
            //  return _setItemWidget('ID ${myId.value.substring(0, 6)}', 0);
          }),
          // JcMineCommentItem(
          //   title: 'Auto Translate',
          //   type: ItemType.translate,
          //   isTranslate: translate,
          // ),
          // _setItemWidget('Auto Translate', 1),
          // _setItemWidget('Logout',2),
          const JcMineCommentItem(
            title: 'Delete Account',
            type: ItemType.delectAccount,
          ),
          // _setItemWidget('Delete Account', 3),
        ],
      ),
    );
  }

  // _setItemWidget(String info, int type) {
  //   return GestureDetector(
  //     child: Container(
  //       height: 56.h,
  //       padding: EdgeInsets.only(left: 19.w, right: 15.w),
  //       margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 20.w),
  //       decoration: BoxDecoration(
  //           color: const Color(0xFFF9F9F9),
  //           borderRadius: BorderRadius.circular(28.h)),
  //       child: Row(
  //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //         crossAxisAlignment: CrossAxisAlignment.center,
  //         children: [
  //           Text(
  //             info,
  //             style: JcTextStyle.octoberDevanagariRegularTextStyle(
  //                 15.sp, Colors.black),
  //           ),
  //           type == 0
  //               ? InkWell(
  //                   child: Image.asset(JcImagePath.jcCopycon),
  //                 )
  //               : const SizedBox(
  //                   width: 0,
  //                 )
  //         ],
  //       ),
  //     ),
  //     onTap: () {
  //       if (type == 3) {
  //         Get.dialog(
  //             JcPop(
  //                 btnTitles: const ['Delete Account'],
  //                 cancelTitle: 'Cancel',
  //                 tapEvents: (index) {
  //                   JcGlobal.of(context).logReport({'page': 'deleteaccount'});
  //                   JsRequest.deleteRequest(success: (res) {
  //                     _deleteResult();
  //                   });
  //                 }),
  //             useSafeArea: false);
  //       }
  //     },
  //   );
  // }

  // _deleteResult() {
  //   var wavaNameRecord = JcCache.getInstance().get('wavaNameRecord');
  //   var wavaUserId = JcCache.getInstance().get('wavaUserId');
  //   if (wavaNameRecord != null) {
  //     List records = jsonDecode(wavaNameRecord);
  //     if (records.isNotEmpty) {
  //       List tmp = [];
  //       for (var element in records) {
  //         if (element['userId'] != wavaUserId) {
  //           tmp.add(element);
  //         }
  //         JcCache.getInstance().setData('wavaNameRecord', jsonEncode(tmp));
  //       }
  //     }
  //   }

  //   var myBwlRecord = JcCache.getInstance().get('myBwlRecord');
  //   if (myBwlRecord != null) {
  //     List bwlRecords = jsonDecode(myBwlRecord);
  //     if (bwlRecords.isNotEmpty) {
  //       List tmp = [];
  //       for (var element in bwlRecords) {
  //         if (element['userId'] != wavaUserId) {
  //           tmp.add(element);
  //         }
  //         JcCache.getInstance().setData('myBwlRecord', jsonEncode(tmp));
  //       }
  //     }
  //   }
  //   Get.back();
  //   Get.toNamed(JcRotePath.jcLogin);
  // }
}
